﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using TByte.XnaHelper.Input;

namespace TByte.XnaHelper.GameObjects
{
    public class GameState
    {
        #region Fields
        string name;
        public event UpdateEventHandler UpdateEvent;
        public event DrawEventHandler DrawEvent;
        public event KeyEventHandler KeyDown;
        public event KeyEventHandler KeyUp;
        public event CharEnteredHandler CharEntered;
        public event MouseEventHandler MouseMove;
        public event MouseEventHandler MouseDown;
        public event MouseEventHandler MouseUp;
        public event MouseEventHandler DoubleClick;
        public event MouseEventHandler MouseHover;
        public event MouseEventHandler MouseWheel;
        GameObject root;
        #endregion

        #region Methods
        public void Update()
        {
            root.Update();

            if (UpdateEvent != null)
                UpdateEvent();
        }
        public void Draw(SpriteBatch spriteBatch)
        {
            root.Draw(spriteBatch);

            if (DrawEvent != null)
                DrawEvent();
        }

        #region InputEvents
        public void OnKeyUp(KeyEventArgs e)
        {
            if (KeyUp != null)
                KeyUp(this, e);
            root.OnKeyUp(e);
        }
        public void OnKeyDown(KeyEventArgs e)
        {
            if (KeyDown != null)
                KeyDown(this, e);
            root.OnKeyDown(e);
        }
        public void OnCharacter(CharacterEventArgs e)
        {
            if (CharEntered != null)
                CharEntered(this, e);
            root.OnCharacter(e);
        }
        public void OnMouseMove(MouseEventArgs e)
        {
            if (MouseMove != null)
                MouseMove(this, e);
            root.OnMouseMove(e);
        }
        public void OnMouseDown(MouseEventArgs e)
        {
            if (MouseDown != null)
                MouseDown(this, e);
            root.OnMouseDown(e);
        }
        public void OnMouseUp(MouseEventArgs e)
        {
            if (MouseUp != null)
                MouseUp(this, e);
            root.OnMouseUp(e);
        }
        public void OnMouseHover(MouseEventArgs e)
        {
            if (MouseHover != null)
                MouseHover(this, e);
            root.OnMouseHover(e);
        }
        public void OnDoubleClick(MouseEventArgs e)
        {
            if (DoubleClick != null)
                DoubleClick(this, e);
            root.OnDoubleClick(e);
        }
        public void OnMouseWheel(MouseEventArgs e)
        {
            if (MouseWheel != null)
                MouseWheel(this, e);
            root.OnMouseWheel(e);
        }
        #endregion

        #endregion

        #region Constructors
        public GameState(string name, GameObject root)
        {
            this.root = root;
            this.name = name;
        }
        #endregion

        #region Properties
        public string Name { get { return name; } }
        public GameObject Root { get { return root; } }
        #endregion
    }
    public delegate void UpdateEventHandler();
    public delegate void DrawEventHandler();
}
